package com.infore.siteManagement.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.infore.siteManagement.dto.EquipmentAndProjectDto;
import com.infore.siteManagement.entity.Equipment;
import com.infore.siteManagement.select.dto.QueryParamDto;
import com.infore.siteManagement.select.util.PageObject;
import com.infore.siteManagement.service.EquipmentService;
import com.infore.siteManagement.util.ResultEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "设备管理接口", tags = {"设备管理接口" })
@RestController
@RequestMapping("/equipment")
public class EquipmentController {
	
	@Autowired
	private EquipmentService equipmentService;

	@ApiOperation(value = "删除设备通用接口")
	@ApiImplicitParams(@ApiImplicitParam(name = "ids", value = "设备id", paramType = "query", required = true, dataType = "String"))
	@DeleteMapping(value = "/delete")
	public ResultEntity deleteEquipmEntity (String ids) {
		return equipmentService.deleteEquipmEntity(ids);
	}
	
	@ApiOperation(value = "查询设备通用接口")
	@ResponseBody
	@PostMapping(value = "/query")
	public ResultEntity queryEquipment(@RequestBody(required = false) QueryParamDto queryParamDto) {
		return equipmentService.queryEquipment(queryParamDto);
	}
	
	@ApiOperation(value = "编辑/新增设备通用接口")
	@ResponseBody
	@PostMapping(value = "/edit")
	public ResultEntity editEquipment(@RequestBody Equipment equipment) {
		return equipmentService.editEquipment(equipment);
	}
	
	@ApiOperation(value = "设备验证通用接口")
	@ResponseBody
	@PostMapping(value = "/validate")
	public ResultEntity validateEquipment(@RequestBody Equipment equipment) {
		return equipmentService.validateEquipment(equipment);
	}
	
	@ApiOperation(value = "国-----新增/编辑仪器设备接口")
	@ResponseBody
	@PostMapping(value = "/addOrEdit")
	public ResultEntity addOrEdit(@RequestBody EquipmentAndProjectDto dto) {
		if (StringUtils.isNotBlank(dto.getId())) {
			return equipmentService.editEquipmentAndProject(dto);
		} else {
			return equipmentService.addEquipmentAndProject(dto);
		}
	}
	
    @ApiOperation("国------查询当前站点下的仪器参数信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "stationCodes", value = "设备编号", paramType = "query", required = true, dataType = "String")})
    @RequestMapping(value = "/queryInstrumentParameters", method = RequestMethod.GET)
    public ResultEntity queryInstrumentParameters(String stationCodes,PageObject page){
         return equipmentService.queryInstrumentParameters(stationCodes,page);
    }
	
}
